﻿using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace BawangMemo.BawangMemoView.View
{
    /// <summary>
    /// LoadView.xaml 的交互逻辑
    /// </summary>
    public partial class LoadView : Window
    {
        [DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
        private static extern int GetSystemMenu(int hwnd, int revert);
        [DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
        private static extern int EnableMenuItem(int menu, int ideEnableItem, int enable);

        private const int SC_CLOSE = 0xF060;
        private const int MF_BYCOMMAND = 0x00000000;
        private const int MF_GRAYED = 0x00000001;
        private const int MF_ENABLED = 0x00000002;

        public void Disable(int handle)
        {
            switch (EnableMenuItem(GetSystemMenu(handle, 0), SC_CLOSE, MF_BYCOMMAND | MF_GRAYED))
            {
                case MF_ENABLED:
                    break;
                case MF_GRAYED:
                    break;
                case -1:
                    throw new Exception("The Close menu item does not exist.");
                default:
                    break;
            }
        }

        private Window introWindow;

        public LoadView(Window introWindow)
        {
            InitializeComponent();
            this.introWindow = introWindow;
        }

        private void Grid_Loaded(object sender, RoutedEventArgs e)
        {
            Disable(new WindowInteropHelper(this).Handle.ToInt32());
        }

    }
}
